﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FPC.Offer.UI.GeneralProcessor.Police_Organize
{
    /// <summary>
    /// Police_OrganizeTalbeshow 的摘要说明
    /// </summary>
    public class Police_OrganizeTalbeshow : IHttpHandler
    {
        FPC.Offer.Service.Police_OrganizeTalbeService s = new Service.Police_OrganizeTalbeService();
        FPC.Offer.Service.Police_FuzzTableService ss = new Service.Police_FuzzTableService();
    
    
        public void ProcessRequest(HttpContext context)
        {
            
            context.Response.ContentType = "text/plain";
            //正常派出所
            var normal_or = (from n in s.Select()
                        join m in ss.Select()
                        on n.AlarmId equals m.AlarmId                  
                        select new
                        {
                            OrganizeId = n.OrganizeId,
                            OrganizeName = n.OrganizeName,
                            LoginName = m.LoginName,
                            LoginPwd = m.LoginPwd,
                            UserPhoto=m.UserPhoto,
                        }).ToList();
               
            //待安排负责人派出所
            var t = s.Select().Where(m => m.AlarmId == 0).ToList();
            var unemployed_or = (from n in t
                      select new
                      {
                          OrganizeId = n.OrganizeId,
                          OrganizeName = n.OrganizeName,
                          LoginName = "待安排负责人",
                          LoginPwd = "待安排负责人",
                          UserPhoto = "待安排负责人",
                      }).ToList();
            //停用派出所
            var tt = s.Select().Where(m => m.AlarmId == -1).ToList();
            var disable_or = (from n in tt
                      select new
                      {
                          OrganizeId = n.OrganizeId,
                          OrganizeName = n.OrganizeName,
                          LoginName = "已停用",
                          LoginPwd = "已停用",
                          UserPhoto = "已停用",
                      }).ToList();
            normal_or.AddRange(unemployed_or);
            normal_or.AddRange(disable_or);
            //出错派出所
            var bb = s.Select();
            foreach (var item in normal_or)
            {
                bb = bb.Where(m => m.OrganizeId != item.OrganizeId).ToList();
            }
            var default_or = (from n in bb
                     select new
                     {
                         OrganizeId = n.OrganizeId,
                         OrganizeName = n.OrganizeName,
                         LoginName = "负责人有误,需重新安排",
                         LoginPwd = "负责人有误,需重新安排",
                         UserPhoto = "负责人有误,需重新安排",
                     }).ToList();
            normal_or.AddRange(default_or);
            context.Response.Write(JsonConvert.SerializeObject(normal_or));        
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}